package concurrent_250224;

public class InterruptSleepExample {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                System.out.println("Thread is sleeping...");
                Thread.sleep(5000); // 线程睡眠 5 秒
                System.out.println("Thread woke up naturally.");
            } catch (InterruptedException e) {
                System.out.println("Thread was interrupted during sleep!");
                // 中断状态已被清除
                System.out.println("Is interrupted after exception: " + Thread.currentThread().isInterrupted());
            }
        });

        thread.start();
        Thread.sleep(1000); // 主线程等待 1 秒
        thread.interrupt(); // 中断线程
    }
}